package com.goods.controller.business;

import com.goods.business.service.OutStockService;
import com.goods.common.error.BusinessException;
import com.goods.common.model.business.OutStockInfo;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.OutStockDetailVO;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @Description: 物资发放记录 出库
 * @Author: Mr.Cao
 * @DateTime: 2021/11/9 17:19
 * BMW F750GS
 **/
@RestController
@RequestMapping("business/outStock/")
public class OutStockController {


    @Autowired
    private OutStockService outStockService;

    /**
     *分页 查询发放记录
     * */
    //http://www.localhost:8989/business/outStock/findOutStockList?pageNum=1&pageSize=10&status=0
    @GetMapping("findOutStockList")
    public ResponseBean findOutStockList(@RequestParam Map queryMap){
       PageVO pageVO =  outStockService.findOutStockList(queryMap);
        return ResponseBean.success(pageVO);
    }
    /**
     * 查询发放明细
     * */
    //http://www.localhost:8989/business/outStock/detail/15?pageNum=1
    @GetMapping("detail/{id}")
    public ResponseBean detail(@PathVariable long id, int pageNum){

        OutStockDetailVO detail = outStockService.detail(id, pageNum);
        return ResponseBean.success(detail);
    }
    /**
     * 新增发放记录
     * */
    //http://www.localhost:8989/business/outStock/addOutStock
    @PostMapping("addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outStockVO, HttpServletRequest request){
        outStockService.addOutStock(outStockVO,request);
        return ResponseBean.success();
    }
    /**
     *通过审核
     * */
    //http://www.localhost:8989/business/outStock/publish/17
    /**
     * 审核通过 --更新库存, 减少库存
     * */
    //http://www.localhost:8989/business/outStock/publish/113
    @PutMapping("publish/{id}")
    public ResponseBean publish(@PathVariable long id) throws BusinessException {
        outStockService.publish(id);
        return ResponseBean.success();
    }
    /**
     * 审核不通过,删除
     * */
    //http://www.localhost:8989/business/outStock/delete/113
    @GetMapping("delete/{id}")
    public ResponseBean delete(@PathVariable long id){
        outStockService.delete(id);
        return ResponseBean.success();
    }
    /**
     * 移除进入回收站
     * */
    //http://www.localhost:8989/business/outStock/remove/111
    @PutMapping("remove/{id}")
    public ResponseBean remove(@PathVariable long id){
        outStockService.remove(id);
        return ResponseBean.success();
    }
    /**
     * 还原: 恢复到正常
     * */
    //http://www.localhost:8989/business/outStock/back/115
    @PutMapping("back/{id}")
    public ResponseBean back(@PathVariable long id){
        outStockService.back(id);
        return ResponseBean.success();
    }
}
